<template>
  <div>
    <div>
      partner
      <van-button type="primary" @click.native="onClick">
        ok
      </van-button>
    </div>
  </div>
</template>

<script>
import { createWorker } from 'tesseract.js'

// import img1 from '@/assets/1.jpeg'

export default {
  name: 'HomeMe',
  components: {},
  directives: {},
  filters: {},

  data() {
    return {}
  },
  computed: {},
  async created() {
    // this.worker = await this.init()
    // await this.test()
    // await this.worker.terminate()
  },

  methods: {
    async init() {
      const worker = createWorker({
        logger: m => {
          console.log('ocr,log, time:', new Date())
          console.log('ocr,log:', m)
        }
      })

      await worker.load()
      await worker.loadLanguage('eng+chi_sim')
      await worker.initialize('eng+chi_sim')

      return worker
    },

    async onClick() {
      this.worker = await this.init()
      await this.test()
      await this.worker.terminate()
    },

    async test() {
      const baseURL = process.env.VUE_APP_BASE_API
      const imgUrl = '/web/image'
      const attachment_id = 407
      // 'http://192.168.56.101:8069/web/image/406'

      const url = `${baseURL}${imgUrl}/${attachment_id}`

      const res = await this.worker.recognize(
        url
        // 'http://localhost:9527/21.jpg'
        // 'https://tesseract.projectnaptha.com/img/eng_bw.png'
      )
      // const {
      //   data: { text }
      // } = res

      console.log(res)
    }
  }
}
</script>

<style type="text/css"></style>
